package com.cax.module.article.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cax.module.article.mapper.ArticleColumnMapper;
import com.cax.module.article.service.ArticleColumnService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.cax.module.article.domain.vo.ArticleColumnVO;
import com.cax.module.article.domain.dto.ArticleColumnDTO;
import com.cax.module.article.domain.ArticleColumn;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;

/**
 * 文章栏目表 Service实现类
 * @author makejava
 * @date 2024-08-22 17:22:38
 */
@Service
@Slf4j
public class ArticleColumnServiceImpl extends ServiceImpl<ArticleColumnMapper, ArticleColumn> implements ArticleColumnService {

	@Autowired
	ArticleColumnMapper articleColumnMapper;

   /**
	 * 查询所有
	 */
	@Override
	public List<ArticleColumnVO> getAll(){
		List<ArticleColumn> list = this.list();
		List<ArticleColumnVO> result = BeanUtil.copyToList(list, ArticleColumnVO.class);
		return result;
	}

	/**
     * 分页查询
     */
	@Override
    public Page<ArticleColumn> getPage(ArticleColumnDTO dto){
		//创建分页对象
		Page<ArticleColumn> page = new Page(dto.getPageNum(), dto.getPageSize());
		//dto查询条件转分页条件
		LambdaQueryWrapper<ArticleColumn> lqw = new LambdaQueryWrapper<>();
		Page<ArticleColumn> result = articleColumnMapper.selectPage(page, lqw);
		return result;
	}

	/**
	 * 通过主键查询
	 */
	@Override
	public ArticleColumnVO getByKey(Integer id){
		ArticleColumn entity = super.getById(id);
		ArticleColumnVO result = BeanUtil.copyProperties(entity, ArticleColumnVO.class);
        return result;
    }

	/**
	 * 添加
	 */
	@Override
	public Integer add(ArticleColumnDTO dto){
		ArticleColumn articleColumn = BeanUtil.copyProperties(dto, ArticleColumn.class);
		this.save(articleColumn);
		return articleColumn.getId();
	}

	/**
	 * 通过主键修改
	 */
	@Override
	public void upd(ArticleColumnDTO dto){
		ArticleColumn articleColumn = BeanUtil.copyProperties(dto, ArticleColumn.class);
	    this.updateById(articleColumn);
	}

}



